package com.lanou.moving.fragment;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.lanou.moving.R;
import com.lanou.moving.adapter.DownloadSingleAdapter;
import com.lanou.moving.base.BaseFragment;
import com.lanou.moving.entity.MusicInfo;
import com.lanou.moving.utils.MyConfig;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 梁树珍 on 15/11/5.
 */
public class SingleMusicFragment extends BaseFragment {
    private ListView song_listview;
    private DownloadSingleAdapter adapter;
    private List<MusicInfo> musicInfoList;
    private MusicInfo musicInfo;
    private Context context;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = getActivity();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.search_song_listview, null);
        song_listview = (ListView) view.findViewById(R.id.song_listview);
        getDatas();
        return view;
    }

    private void getDatas() {
        if (musicInfo == null){
            return;
        }else {
            String songName = MyConfig.getSharePreStr(context, "songName", "songName");
            String singerName = MyConfig.getSharePreStr(context, "singerName", "singerName");
            String url = MyConfig.getSharePreStr(context, "download_url", "download_url");
            musicInfo = new MusicInfo();
            musicInfo.setSongName(songName);
            musicInfo.setSingerName(singerName);
            musicInfo.setUrl(url);
            musicInfoList = new ArrayList<>();
            musicInfoList.add(musicInfo);
            adapter = new DownloadSingleAdapter(context, musicInfoList);
            song_listview.setAdapter(adapter);
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
